package com.zjdiepu.www.rest.api.other;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.zjdiepu.www.base.BaseController;
import com.zjdiepu.www.base.annotation.Add;
import com.zjdiepu.www.base.core.ApiResponse;
import com.zjdiepu.www.base.enums.status.DpStatus;
import com.zjdiepu.www.common.consts.SystemConsts;
import com.zjdiepu.www.commpent.handler.TokenUserHelper;
import com.zjdiepu.www.ibiz.other.IOtherSimpleInfoService;
import com.zjdiepu.www.model.base.dto.SysUser;
import com.zjdiepu.www.model.other.dto.OtherSimpleInfo;
import com.zjdiepu.www.model.other.request.GetSimpleInfoRequest;
import com.zjdiepu.www.model.third.response.CarModelResponse;

/**
 * other_简单信息表,一些简单的记录型数据统一写在这,用modeid区分Controller层<br/>
 * @author xiongxiaotun<br/>
 * @time 2018年01月09日 11时24分<br/>
 * @since 1.0<br/>
 */
@RestController
@RequestMapping(value = "OtherSimpleInfoController", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
@Api(tags = { "简单信息表" }, produces = "application/json;charset=UTF-8")
public class OtherSimpleInfoController extends BaseController {
    @Resource
    private IOtherSimpleInfoService otherSimpleInfoService;
    @Resource
    private TokenUserHelper tokenUserHelper;
    
    /**
     * @author xiongxiaotun <br/>
     * @Title: savePostSupplement  <br/>
     * @Description: 保存后补资料 <br/>
     * @param otherSimpleInfo
     * @return
     * @version V1.0  <br/>
     */
    @ApiOperation(value = "保存后补资料", response = Boolean.class, httpMethod="POST")
    @ApiImplicitParams({
		@ApiImplicitParam(name = SystemConsts.MOBILE_FLAG, defaultValue = "ios", value = "请求机器标识", required = true, paramType = "header", dataType = "String"),
		@ApiImplicitParam(name = SystemConsts.HEADER_FOR_TOKEN, defaultValue = "Ajesget8XF7zNMpt+MM8cr0wI8S+IO6a9giEKNouXWvOO3wWWyaKjSDTqRUtHlcNbjCg1JaPdjRX6dX/O1oGLgE=", value = "token", required = true, paramType = "header", dataType = "String") })
    @RequestMapping(value = "savePostSupplement", method = RequestMethod.POST)
    public ApiResponse savePostSupplement(@Validated(Add.class) @RequestBody OtherSimpleInfo otherSimpleInfo) {
    	SysUser currentUser = tokenUserHelper.getUser();
    	otherSimpleInfoService.savePostSupplement(currentUser, otherSimpleInfo, true);
        return ApiResponse.success(otherSimpleInfo.getId());
    }

    /**
	 * @author xiongxiaotun <br/>
	 * @Title: getByBusiId <br/>
	 * @Description: 获取后补资料<br/>
	 * @param parentModel
	 * @return
	 * @version V1.0 <br/>
	 */
	@ApiOperation(value = "获取后补资料", response = CarModelResponse.class, httpMethod = "POST")
	@ApiImplicitParams({
			@ApiImplicitParam(name = SystemConsts.MOBILE_FLAG, defaultValue = "ios", value = "请求机器标识", required = true, paramType = "header", dataType = "String"),
			@ApiImplicitParam(name = SystemConsts.HEADER_FOR_TOKEN, defaultValue = "Ajesget8XF7zNMpt+MM8cr0wI8S+IO6a9giEKNouXWvOO3wWWyaKjSDTqRUtHlcNbjCg1JaPdjRX6dX/O1oGLgE=", value = "token", required = true, paramType = "header", dataType = "String") })
	@RequestMapping("getByBusiId")
	public ApiResponse getByBusiId(@Validated @RequestBody GetSimpleInfoRequest getSimpleInfoRequest) {
       OtherSimpleInfo otherSimpleInfo = new OtherSimpleInfo();
       otherSimpleInfo.setDpStatus(DpStatus.NORMAL.getCode());
       otherSimpleInfo.setBusiId(getSimpleInfoRequest.getBusiId());
       otherSimpleInfo.setModeId(getSimpleInfoRequest.getModeId());
       otherSimpleInfo = otherSimpleInfoService.selectRefined(otherSimpleInfo);
       return ApiResponse.success(otherSimpleInfo);
	}
}
